#include <stdio.h>
#include <stdlib.h>
#include "funch.h"
#define erro "Parametros de entrada fora do padrao\n"

int main(int argc, char** argv)
{
	int count=0, i=0;	
  ///////////////////////// AQUIIIIIIIIIIIIIIIIIIIIIIII
	int n =0;
	char** aptarray;
  char** aptarg;
    ///////////////////////// AQUIIIIIIIIIIIIIIIIIIIIIIII
  char* palavras;
	ap_list list=NULL;
	
	aptarg=abre_pega("file.txt");
  if(aptarg==NULL)
  {
    printf(erro);
    system("PAUSE");
    return 0;
  }
  else
  {
    char *straux1 = aptarg[0];
    char *str1 = (char *)malloc((strlen(straux1)+1)*sizeof(char));
    str_spaces(straux1,str1);
    alfanum(str1);
    
    str_spaces(str1,str1);
    
    char *straux2 = aptarg[1];
    char *str2 = (char *)malloc((strlen(straux2)+1)*sizeof(char));
    str_spaces(straux2,str2);
    
		char *straux3 = aptarg[2];
    char *str3 = (char *)malloc((strlen(straux3)+1)*sizeof(char));
    str_spaces(straux3,str3);
    
		str_upper(str1,strlen(str1));
    str_upper(str2,strlen(str2));
    str_upper(str3,strlen(str3));	
    
    str_upper(aptarg[0],strlen(aptarg[0]));
    str_upper(aptarg[1],strlen(aptarg[1]));
    str_upper(aptarg[2],strlen(aptarg[2]));
    
    i=charfrequency(aptarg[0],aptarg[1]);
    
    printf("Texto de entrada: %s\n", str1);
    printf("Caractere: %c\n", *str2);
    printf("Palavra: %s\n", str3);

    aptarray = strtoken(str1, &count);
    
		printf("O texto possui %d palavra(s).\n", count);
		
    list=list_freq(aptarray, count);  

    palavras = strtoken2(aptarg[0]);
   printf("%s\n", palavras);
    printf("alo mamae %s\n", aptarg[0]);
/*  for (i=0;i<5;i++){

    printf("alo mamae %s\n", palavras[i]);
  }
  */
    free(str1);
	  free(str2);
  	free(str3);
  }
  printf("O caracter '%s' aparece %d vezes no texto.\n", aptarg[1],i);
  printf("A palavra '%s' aparece %d vezes no texto.\n", aptarg[2], strfrequency(aptarg[0],aptarg[2]));
  free_malloc(list);
  free(aptarray);
  free(aptarg[3]);
  free(aptarg);
  system("PAUSE");
	return 0;
}
